package behavioral.observer;
import java.util.ArrayList;
import java.util.List;

public class ConcreteSubject implements Subject {
    private List<Observer> list = new ArrayList<Observer>();
    private String mSubjectState;

    public void attach(Observer observer) {
        list.add(observer);
    }

    public void detach(Observer observer) {
        list.remove(observer);
    }

    public void notify(String newState) {
        for (Observer observer : list) {
            observer.update(newState);
        }
    }

    public void change(String newState) {
        mSubjectState = newState;
        notify(mSubjectState);
    }
}
